/*
 * Font.cpp
 *
 *  Created on: Jul 18, 2009
 *      Author: kurt
 */

#include "Font.h"
#include <intraFont.h>
#include <cstdarg>
#include <cstdlib>
using namespace std;
using namespace objdraw;

bool Font::intraFontInited = false;

int Font::initIntraFont()
{
	int r = 1;
	if(!intraFontInited)
		r = intraFontInit();
	if(r == 1)
		intraFontInited = true;
	else
		intraFontInited = false;
	return r;
}
void Font::shutdownIntraFont()
{
	intraFontShutdown();
	intraFontInited = false;
}
Font::Font(const Font & f)
{
	
}
Font::~Font() 
{
	if(font != NULL)
		intraFontUnload(font);
	font = NULL;
}

Font::Font() 
{
	initIntraFont();
	font = NULL;
}
Font::Font(string file, unsigned int opts)
{
	initIntraFont();
	font = intraFontLoad((char *)file.c_str(),opts);
}
void Font::activate()
{
	if(font != NULL)
		intraFontActivate(font);
}
void Font::setStyle(float size, Color color, Color shadowColor, unsigned int options)
{
	if(font != NULL)
		intraFontSetStyle(font,size,color.gu_c(),shadowColor.gu_c(),options);
}
void Font::setEncoding(unsigned int options)
{
	if(font != NULL)
		intraFontSetEncoding(font,options);
}
void Font::setAlternateFont(Font * f)
{
	if(font != NULL && f != NULL)
		intraFontSetAltFont(font,f->font);
}
bool Font::fontIsLoaded()
{
	return font == NULL ? false : true;
}
intraFont * Font::getFont()
{
	return font;
}
float Font::printUCS2(float x, float y, const unsigned short int * text)
{
	if(font != NULL)
		return intraFontPrintUCS2(font,x,y,text);
	return 0.0f;
}
float Font::printUCS2Ex(float x, float y, const unsigned short int * text, int length)
{
	if(font != NULL)
		return intraFontPrintUCS2Ex(font,x,y,text,length);
	return 0.0f;
}
float Font::printColumnUCS2(float x, float y, float width, const unsigned short int * text)
{
	if(font != NULL)
		return intraFontPrintColumnUCS2(font,x,y,width,text);
	return 0.0f;
}
float Font::printColumnUCS2Ex(float x, float y, float width, const unsigned short int * text, int length)
{
	if(font != NULL)
		return intraFontPrintColumnUCS2Ex(font,x,y,width,text,length);
	return 0.0f;
}
float Font::print(float x, float y, const char * text)
{
	if(font != NULL)
		return intraFontPrint(font,x,y,text);
	return 0.0f;
}
float Font::printf(float x, float y, const char * text, ...)
{
	if(font != NULL)
	{
		char buff[500];
		va_list args;
		va_start(args,text);
		vsprintf(buff,text,args);
		va_end(args);
		return intraFontPrintf(font,x,y,buff);
	}
	return 0.0f;
}
float Font::measureText(const char * text)
{
	if(font != NULL)
		return intraFontMeasureText(font,text);
	return 0.0f;
}
float Font::measureTextEx(const char * text, int length)
{
	if(font != NULL)
		return intraFontMeasureTextEx(font,text,length);
	return 0.0f;
}
float Font::measureTextUCS2(const unsigned short int * text)
{
	if(font != NULL)
		return intraFontMeasureTextUCS2(font,text);
	return 0.0f;
}
float Font::measureTextUCS2Ex(const unsigned short int * text, int length)
{
	if(font != NULL)
		return intraFontMeasureTextUCS2Ex(font,text,length);
	return 0.0f;
}
